//
//  RSViewController.m
//  RSTools
//
//  Created by thinkjoy on 2017/10/20.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "RSViewController.h"
#import "NSObject+RSCalculator.h"
#import "RSCalculator.h"

#import "RSFunCalculator.h"
#import "ReactiveObjC.h"

//#import <ReactiveObjC\ReactiveObjC.h>

@interface RSViewController ()
@property (weak, nonatomic) IBOutlet UIButton *butt;

@end

@implementation RSViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    RSCalculator *calculator = [[RSCalculator alloc] init];
    NSInteger result    =   calculator.add(5).subtract(1).multiply(10).divide(5).add(100).result;
    NSLog(@"result=%ld",result);
    
    result  =   [self makeCaculators:^(RSCalculator *make) {
        make.add(5).subtract(1).multiply(10).divide(5).add(100);
    }];
    NSLog(@"result==%ld",result);

    [[_butt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        NSLog(@"按钮被点击");
    }];
    
    //RACSignal * signal  =
    [[RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        [subscriber sendNext:@"ceshi"];
        return nil;
    }] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
    RACSubject * subject    =   [RACSubject subject];
    [subject subscribeNext:^(id  _Nullable x) {
        NSLog(@"第一个订阅者%@",x);
    }];
    
    [subject subscribeNext:^(id  _Nullable x) {
        NSLog(@"第er个订阅者%@",x);
    }];
    
    [subject sendNext:@"1111111"];
    
    RACReplaySubject    * replaySubject0 =   [RACReplaySubject subject];
    
    [replaySubject0 subscribeNext:^(id  _Nullable x) {
        NSLog(@"replaySubject0_1%@",x);
    }];
    [replaySubject0 subscribeNext:^(id  _Nullable x) {
        NSLog(@"replaySubject0_2%@",x);
    }];
    [replaySubject0 sendNext:@"RACReplaySubject111"];
    [replaySubject0 sendNext:@"RACReplaySubject2222"];
    
    
    // 1.创建信号
    RACReplaySubject *replaySubject = [RACReplaySubject subject];
    
    // 2.发送信号
    [replaySubject sendNext:@1];
    [replaySubject sendNext:@2];
    
    // 3.订阅信号
    [replaySubject subscribeNext:^(id x) {
        
        NSLog(@"第一个订阅者接收到的数据%@",x);
    }];
    
    // 订阅信号
    [replaySubject subscribeNext:^(id x) {
        
        NSLog(@"第二个订阅者接收到的数据%@",x);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
